var sxId = $("#sxId").val();
var incId = $("#incId").val();
var submitFlag = 1;

var increaseType = $("#increaseType").val();
if(increaseType == 'decrease'){
	$('.applyTipId').html("降额申请");
	$('.applyAmountTipId').html("审批降额金额：");
	$('.DetailTipId').html("降额申请详情");
	$('.applyAmountDetailTipId').html("申请降额：");
	$('.creditIncreaseId').html("授信审批减额：");
}

function bindPrompt(isPass){
	if('true'== isPass){
		$("#title").html("提额授信审批");
		$("#passDiv").show();
		$("#noPassDiv").hide();
		$("#remark").val("ok");
	}else if('false' ==isPass){
		$("#remark").val("");
		$("#title").html("驳回原因");
		$("#passDiv").hide();
		$("#noPassDiv").show();
		$("#realCredit").val(0);
	}
	$("#isPass").val(isPass);
	
	var sxId = $("#sxId").val();
	$('#my-prompt').modal({
	    relatedTarget: this,
	    closeViaDimmer:false,
	    onConfirm: function(e) {
	    	if('false' == $("#isPass").val() && !$("#remark").val()){
	    		layer.msg("驳回原因不能为空", { icon : 0 });
	    		return;
	    	}
	    	if(submitFlag == 0){
	    		layer.msg("不可重复提交", {icon : 0});
	    		return;
	    	}
	    	if('true' == isPass && (parseInt($("#userCredit").html())+parseInt($("#passAmount").val())) >50000 && $("#increaseType").val() != "decrease" ){
	    		layer.confirm('提额后用户额度超过50000,确认提额？', {
	    	        icon : 3,
	    	        title : '用户额度超过50000'
	    	    }, function(index, layero) {
	    	        layer.close(index);
	    	        submitFrom();
	    	    });
	    		return;
	    	}else{
	    		submitFrom();
	    	}
	    },
	    onCancel: function(e) {
	    }
	    
	  });
	
}  

function submitFrom(){
	console.log('submitFrom in');
	submitFlag = 0;
	$.ajax({
		url:"credit/auditIncreaseLimit/"+sxId+"/"+incId+"/"+$("#isPass").val() +"/"+$("#passAmount").val()+"/"+$("#remark").val()+"/",
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			submitFlag = 1;
			if(data.ret==200 && data.content && data.content.code==10000){
		         layer.msg(data.message, {
                        icon : 1
                 });
		         $('#my-prompt').modal('close');
		         loadPage("credit/preAuditUI"); 
			}else{
				var msg;
				if(data.content && data.content.msg){
					msg = data.content.msg;
				}else{
					msg = data.message;
				}
				layer.msg(msg, { icon : 0 });
			}
		},
		error:function(data){
			submitFlag = 1;
		}  
	});
}

function check(pic){
	$("#imgId").attr('src',pic); 
	$('#doc-modal-1').modal();
}